import { createApp } from 'vue'
import axios from 'axios'
import App from './App.vue'
import router from './router'
import store from './store'

axios.defaults.baseURL = 'https://www.fastmock.site/mock/77a51050fe27c1bac7c3a8b47fcf0d48/zy'
// axios.defaults.baseURL = process.env.NODE_ENV === 'development' ? 'http://localhost:8080/api/' : 'https://www.fastmock.site/mock/77a51050fe27c1bac7c3a8b47fcf0d48/zy'
// axios拦截器
axios.interceptors.request.use(config => {
  // config.params = { ...config.params, icode: '623HJ576YUCHF567DBS' }
  // 添加loading效果
  store.commit('setLoading', true)
  store.commit('setError', { status: false, message: '' })
  return config
})
// axios拦截器
axios.interceptors.response.use(config => {
  // 添加loading效果
  store.commit('setLoading', false)
  return config
}, e => {
  const { error } = e.response.data
  store.commit('setError', { status: true, message: error })
  store.commit('setLoading', false)
  return Promise.reject(error)
})

createApp(App).use(store).use(router).mount('#app')
